#!/bin/bash

if [[ $# -ne 1 ]]; then
    echo "The format is as follows:"
    echo "bash bismark-.sh installpath "
    echo ":param installpath: 应用安装绝对路径"
    exit 1
fi

[[ ! "$1" =~ ^/.* || "$1" = "/" ]] &&  echo "请输入正确的安装路径" && exit 1

installpath=$1
[[ "$installpath" =~ .*/$ ]] && installpath=${installpath%/*}

yum install -y  environment-modules csh time patch libatomic perl

set -e
wget -t 0 -c -P $installpath https://github.com/FelixKrueger/Bismark/archive/refs/tags/v0.16.2.tar.gz
tar xf $installpath/v0.16.2.tar.gz -C $installpath && rm -rf $installpath/v0.16.2.tar.gz
cat>"$installpath/Bismark-0.16.2/bismark_modulefiles"<<EOF
#%Module1.0
conflict bismark
variable modfile [file normalize [info script]]
proc getModulefileDir {} {
    variable modfile
    set modfile_path [file dirname \$modfile]
    return \$modfile_path
}
set pwd [getModulefileDir]
set BISMARK \$pwd
setenv BISMARK \$BISMARK
prepend-path PATH \$BISMARK
EOF
